<script setup lang="ts">
import img1 from "./assets/1.jpg?url";
import img2 from "./assets/2.jpg?url";
import img3 from "./assets/3.jpg?url";
import { onMounted, provide, type Ref, ref } from "vue";
import type { ITea } from "./types/ITea.ts";
import logoUrl from "./assets/logo.png";
import { useRouter } from "vue-router";

// ! 依赖注入 已经停止使用了
const navs: Ref<ITea[]> = ref([
  { id: 1,title: "杭州龙井", description: "鲜爽口感, 淡雅香气", imgSrc: img1, price:0 },
  { id: 2,title: "黄山毛峰", description: "色泽嫩黄, 茶汤清澈", imgSrc: img2, price:0 },
  { id: 3,title: "苏州碧螺春", description: "测试", imgSrc: img2,price:0 },
  { id: 4,title: "安溪铁观音", description: "测试", imgSrc: img2,price:0 },
  { id: 5,title: "庐山云雾", description: "测试", imgSrc: img2,price:0 },
  { id: 6,title: "白毫银针", description: "测试", imgSrc: img2,price:0 },
  { id: 7,title: "武夷岩茶", description: "测试", imgSrc: img2,price:0 },
  {
    id: 8,
    title: "普洱茶",
    description:
      "普洱茶以其浓厚的口感和独特的陈香著称。其茶叶经过发酵处理, 色泽褐红, 茶汤深沉, 具有独特的醇厚滋味和健康功效。",
    imgSrc: img3,
    price:0
  }
]);
provide("teas", navs);

const router = useRouter();
const headerClassList = ref<string[]>([]);

const clickGoToHome = () => {
  router.push({path: "/"});
}

onMounted(() => {
  // 判断滑动方向
  document.addEventListener("wheel", e => {
    if (e.deltaY > 30) {
      if(headerClassList.value.length == 0) {
      headerClassList.value.push("header-down");}
    } else {
      headerClassList.value.pop();
    }
  });
});
</script>

<template>
  <!-- *** header start *** -->
  <header class="header" :class="headerClassList">
    <div class="logo-wrapper" @click="clickGoToHome">
      <img class="logo" :src="logoUrl" alt="十大名茶" />
      <span>八大名茶</span>
    </div>
    <ul class="nav">
      <li><a>产品中心</a></li>
      <li><a>品牌动向</a></li>
      <li><a>企业招聘</a></li>
    </ul>
  </header>
  <!-- *** header end *** -->
  <RouterView />
  <!-- *** footer start *** -->
  <footer class="footer-wrapper">
    <div class="footer">
      <!-- *** footer right start *** -->
      <div class="footer-2">
        <div>
          <h4>帮助中心</h4>
          <ul>
            <li>客服服务</li>
            <li>举报投诉</li>
            <li>常见问题</li>
          </ul>
        </div>
        <div>
          <h4>关于八大名茶</h4>
          <ul>
            <li>关于网站</li>
            <li>网站备案信息</li>
            <li>常见问题</li>
          </ul>
        </div>
      </div>
    </div>
    <!-- *** footer right end *** -->
    <p style="font-size: 0.5rem; color: #cdcdcd">
      版权所有© 八大茶叶茶业有限公司 2000-{{ new Date().getFullYear() }}
    </p>
  </footer>
  <!-- *** footer end *** -->
</template>

<style scoped>
.header {
  height: 80px;
  line-height: 80px;
  width: 100%;
  padding: 0 10%;
  box-sizing: border-box;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  position: fixed;
  z-index: 10;
  top: 0;
  background: white;
}

.header-down {
  border-bottom: 1px solid #e1e1e1;
}

.logo-wrapper {
  height: 40px;
  line-height: 40px;
  cursor: pointer;
}

.logo {
  height: 40px;
  border-radius: 25px;
  overflow: hidden;
  vertical-align: middle;
  margin-right: 8px;
}

.nav li {
  padding: 0 12px;
  display: inline-block;
}

.nav li a {
  cursor: pointer;
  user-select: none;
}


.footer-wrapper {
  background: #242424;
  padding: 20px 10%;
  color: white;
  text-align: center;
}

.footer {
  display: flex;
  flex-direction: row-reverse;
  text-align: left;
}

.footer-1 p {
  color: #cdcdcd;
  font-size: 12px;
}

.footer-2 {
  display: flex;
  flex-direction: row;
  gap: 6rem;
  font-size: 1.5rem;
}


.footer-2 div:last-child {
  margin-right: 0;
}

.footer-2 div li {
  font-size: 1rem;
  color: #cdcdcd;
}
</style>
